import { createRouter, createWebHashHistory } from 'vue-router'
import {
  ElButton,
  ElForm,
  ElFormItem,
  ElInput,
  ElMessage,
  ElMessageBox,
  ElNotification,
  ElPopconfirm,
  ElTable,
  ElTableColumn,
  ElTooltip,
} from "element-plus";
import HomeView from "../views/HomeView.vue";
import LoginView from "../views/LoginView.vue";
import RegisterView from "../views/RegisterView.vue";
import TypeView from "../views/TypeView.vue";
import Layout from "../views/Layout.vue";
import UserProfileView from "../views/UserProfileView.vue";
import SearchView from "../views/SearchView.vue";
import YardDetailsView from "../views/YardDetailsView.vue";
import Orders from "../components/Orders.vue";
import ReserveView from "../views/ReserveView.vue";
import  record from "../components/record.vue";

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "home",
      component: HomeView,
    },
    {
      path: "/Manager",
      name: "UserCenter",
      component: () => import("../views/UserIndexView.vue"),
      redirect: "/home", // 重定向到主页
      children: [
        {
          path: "/403",
          name: "Auth",
          meta: { name: "无权限" },
          component: () => import("../views/manager/Auth.vue"),
        },
        {
          path: "/UserIndex",
          name: "center",
          meta: { name: "个人中心" },
          component: () => import("../views/UserIndexView.vue"),
        },
        { path: '/notice',
          name: 'Notice',
           meta: { name: '系统公告' }, 
           component: () => import('../components/Notice.vue')
          },
       {
          path: "/user",
          name: " UserProfile",
          meta: { name: "用户信息" },
          component: () => import("../views/manager/UserProfileView.vue"),
        },
        // { path: '/person', name: 'Person', meta: { name: '个人信息' }, component: () => import('../views/manager/Person.vue') },
        // { path: '/password', name: 'Password', meta: { name: '修改密码' }, component: () => import('../views/manager/Password.vue') },
        {
          path: "/news",
          name: "News",
          meta: { name: "场地使用信息" },
          component: () => import("../views/manager/News.vue"),
        },
        
        // { path: '/newsDetail', name: 'NewsDetail', meta: { name: '详情' }, component: () => import('../views/manager/NewsDetail.vue') },
        
        // { path: '/logs', name: 'Logs',meta: { name: '系统日志' }, component: () => import('../views/manager/Logs.vue') },
        // { path: '/charts', name: 'Charts', meta: { name: '数据统计' }, component: () => import('../views/manager/Charts.vue') },
        // {
        //   path: "/orders",
        //   name: "Orders",
        //   meta: { name: "订单管理" },
        //   component: () => import("../components/Orders.vue"),
        // },
        {
          path: "**",
          name: "404",
          meta: { name: "无法访问" },
          component: () => import("../views/404.vue"),
        },
      ],
    },

    {
      path: "/Layout",
      name: "layout",
      component: Layout,
    },
    {
      path: "/login",
      name: "Login",
      component: LoginView,
    },

    {
      path: "/register",
      name: "register",
      component: RegisterView,
    },

    {
      path: "/type",
      name: "Type",
      component: TypeView,
    },
    {
      path: "/orders",
      name: "Orders",
      component: Orders,
    },
    {
      path: "/record",
      name: "Record",
      component: record,
    },

    // {
    //   path: '/user',
    //   name: 'UserProfile',
    //   component: UserProfileView
    // },

    {
      path: "/search",
      name: "Search",
      component: SearchView,
    },

    {
      path: "/yardDetails",
      name: "YardDetails",
      component: YardDetailsView,
      props: true,
    },
    {
      path: "/admin",
      name: "Admin",
      meta: { name: "管理员" },
      component: () => import("../views/AdminView.vue"),
    },

    {
      path: "/reserve",
      name: "reserve",
      component: ReserveView,
    },
  ],
});

// router.beforeEach((to, from, next) => {
//   // to 是到达的路由信息
//   // from 是开源的路由信息
//   // next 是帮助我们跳转路由的函数
//   let adminPaths = ['/user']
//   let user = JSON.parse(localStorage.getItem('honey-user') || '{}')

//   if (user.role !== '管理员' && adminPaths.includes(to.path)) {
//     // 如果当前登录的用户不是管理员，然后当前的到达的路径是管理员才有权限访问的路径，那这个时候我就让用户去到一个没有权限的页面，不让他访问实际的页面
//     next('/403')
//   } else {
//     next()
//   }
// })

export default router;
